<?php
namespace app\index\controller;
use think\Session;
/**
 * 文章类
 */
class Article extends Api
{
	public function init(){
		if(!model('Users')->checkLogin()){
			$this->redirect('/user/index');
			return ;
		}		
	}
	public function getList(){
		$list = model('Articles')->all(['uid' => Session::get('wx_user.id')]);
		return $this->fetch('index', ['list' => $list]);		
	}
	
	public function getCreate(){
	    return $this->fetch('create');
	}
	
	public function postSave(){
	   $re = model('Articles')->addArticle($this->request->post(['uid' => Session::get('wx_user.id')]));
	   return json($re);
	}
	
	public function postUpload(){
	    // 获取表单上传文件 例如上传了001.jpg
	    $file = request()->file('fileVal');
	    // 移动到框架应用根目录/public/uploads/ 目录下
	    $info = $file->validate(['size'=>1 * 1024 * 1024,'ext'=>'png,jpeg,jpg,gif'])->move(ROOT_PATH . 'public' . DS . 'static'. DS .'uploads');
	    if($info){
	    	$url = DS.'uploads'.DS.$info->getSaveName();
	        return json(['url' => $url]);
	    }else{
	        return 0;
	    }
	}
	
}
 
 
?>